package com.mfin.bs.services;

import com.mfin.bs.mgr.impl.TransactionManager;
import com.mfin.bs.mgr.interfaces.IFinanceInformationManager;
import com.mfin.bs.mgr.interfaces.ITransactionManager;
import com.mfin.vo.CustomerListVO;
import com.mfin.vo.CustomerVO;
import com.mfin.vo.PartnerListVO;
import com.mfin.vo.PartnerVO;
import com.mfin.vo.UserVO;
import com.mfin.vo.finance.FinanceVO;

public class FinanceServicesImpl extends BaseImpl implements IFinanceServices {

	@Override
	public FinanceVO createFinance(FinanceVO finance) {

		logMethodBegin("FinanceServicesImpl", "createMainBranch");

		ITransactionManager transaction = new TransactionManager();
		transaction.beginTransaction();

		IFinanceInformationManager parentFinanceManager = getFinanceManager(transaction
				.getPersistenceGovernor());
		FinanceVO updateBranchVO = parentFinanceManager
				.createFinance(finance);

		transaction.commitTransaction();
		logMethodEnd("FinanceServicesImpl", "createMainBranch");
		return updateBranchVO;
	}

	@Override
	public CustomerVO addCustomer(FinanceVO finance, CustomerVO customer) {

		logMethodBegin("FinanceServicesImpl", "addCustomer");

		ITransactionManager transaction = new TransactionManager();
		transaction.beginTransaction();

		IFinanceInformationManager financeManager = getFinanceManager(transaction
				.getPersistenceGovernor());
		CustomerVO updatedCustomerVO = financeManager.addCustomer(finance,
				customer);

		transaction.commitTransaction();
		logMethodEnd("FinanceServicesImpl", "addCustomer");
		return updatedCustomerVO;
	}

	@Override
	public FinanceVO getFinance(FinanceVO financeVO) {

		logMethodBegin("FinanceServicesImpl", "getFinance");

		ITransactionManager transaction = new TransactionManager();
		transaction.beginTransaction();

		IFinanceInformationManager parentFinanceManager = getFinanceManager(transaction
				.getPersistenceGovernor());
		FinanceVO updateBranchVO = parentFinanceManager.getFinance(financeVO);

		transaction.commitTransaction();
		logMethodEnd("FinanceServicesImpl", "getFinance");
		return updateBranchVO;
	}

	@Override
	public FinanceVO updateFinance(FinanceVO financeVO) {
		logMethodBegin("FinanceServicesImpl", "updateFinance");

		ITransactionManager transaction = new TransactionManager();
		transaction.beginTransaction();

		IFinanceInformationManager parentFinanceManager = getFinanceManager(transaction
				.getPersistenceGovernor());
		FinanceVO updateFinance = parentFinanceManager
				.updateFinance(financeVO);

		transaction.commitTransaction();
		logMethodEnd("FinanceServicesImpl", "updateFinance");
		return updateFinance;
	}

	@Override
	public PartnerVO addPartner(FinanceVO financeVO, PartnerVO partnerVO) {
		logMethodBegin("FinanceServicesImpl", "addPartner");

		ITransactionManager transaction = new TransactionManager();
		transaction.beginTransaction();

		IFinanceInformationManager financeManager = getFinanceManager(transaction
				.getPersistenceGovernor());
		PartnerVO updatedPartnerVO = financeManager.addPartner(financeVO,partnerVO);

		transaction.commitTransaction();
		logMethodEnd("FinanceServicesImpl", "addPartner");
		return updatedPartnerVO;
	}

	@Override
	public UserVO createUser(FinanceVO financeVO, UserVO userVO) {
		logMethodBegin("FinanceServicesImpl", "createUser");

		ITransactionManager transaction = new TransactionManager();
		transaction.beginTransaction();

		IFinanceInformationManager financeManager = getFinanceManager(transaction
				.getPersistenceGovernor());
		UserVO updatedUserVO = financeManager.createUser(financeVO,
				userVO);

		transaction.commitTransaction();
		logMethodEnd("FinanceServicesImpl", "createUser");
		return updatedUserVO;
	}

	@Override
	public FinanceVO getFinance(UserVO userVO) {

		logMethodBegin("FinanceServicesImpl", "getFinance");

		ITransactionManager transaction = new TransactionManager();
		transaction.beginTransaction();

		IFinanceInformationManager parentFinanceManager = getFinanceManager(transaction
				.getPersistenceGovernor());
		FinanceVO updateBranchVO = parentFinanceManager.getFinance(userVO);

		transaction.commitTransaction();
		logMethodEnd("FinanceServicesImpl", "getFinance");
		return updateBranchVO;
	}

	@Override
	public CustomerListVO getFinanceCustomers(FinanceVO financeVO) {
		logMethodBegin("FinanceServicesImpl", "getAllCustomers");

		ITransactionManager transaction = new TransactionManager();
		transaction.beginTransaction();

		IFinanceInformationManager financeManager = getFinanceManager(transaction
				.getPersistenceGovernor());
		CustomerListVO customerListVO = financeManager
				.getFinanceCustomers(financeVO);

		transaction.commitTransaction();
		logMethodEnd("FinanceServicesImpl", "getAllCustomers");
		return customerListVO;
	}

	@Override
	public PartnerListVO getFinancePartners(FinanceVO financeVO) {
		logMethodBegin("FinanceServicesImpl", "getFinancePartners");

		ITransactionManager transaction = new TransactionManager();
		transaction.beginTransaction();

		IFinanceInformationManager financeManager = getFinanceManager(transaction
				.getPersistenceGovernor());
		PartnerListVO partnerListVO = financeManager.getFinancePartners(financeVO);

		transaction.commitTransaction();
		logMethodEnd("FinanceServicesImpl", "getFinancePartners");
		return partnerListVO;
	}
}
